package com.lv.service.dialog

import android.content.Context
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lv.service.R

import com.lv.service.bean.CommonNameBean
import com.lxj.xpopup.core.BottomPopupView

/**
 * 作者： ygx
 * 创建日期：2022/10/10 10:32 AM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 * -    _              _           _     _   ____  _             _ _
 * -   / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 * -  / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 * - / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 * -/_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 *
 *
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 * 描述：
 */
class ParameterPopupView(
    private val mContext: Context,
    private val mAllCategory: List<CommonNameBean>? = null,
//    private var onPopSureListener: OnPositionTListener<CommonNameBean>?
) :
    BottomPopupView(mContext) {
    private val current = 0
    private val name = ""
    private var rvContent: RecyclerView? = null
    private var viewTop: View? = null
    private val mCategorys = mutableListOf<CommonNameBean>()

    private var mAdapter: BaseQuickAdapter<CommonNameBean, BaseViewHolder>? = null
    override fun getImplLayoutId(): Int {
        return R.layout.goods_parameter_popup
    }

    override fun onCreate() {
        super.onCreate()
        rvContent = findViewById<RecyclerView>(R.id.rv_content)
        viewTop = findViewById<View>(R.id.view_top)
        findViewById<ImageView>(R.id.iv_close).setOnClickListener { dismiss() }
        findViewById<TextView>(R.id.tv_finish).setOnClickListener { dismiss() }

        initView()
        initEvnet()
    }

    private fun initView() {
        mAllCategory?.let {
            mCategorys.clear()
            mCategorys.addAll(mAllCategory)
        }

        val mLinearLayoutManager =
            LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false)
        rvContent?.layoutManager = mLinearLayoutManager
        mAdapter = object : BaseQuickAdapter<CommonNameBean, BaseViewHolder>
            (R.layout.item_parameter_goods, mCategorys) {
            override fun convert(holder: BaseViewHolder, item: CommonNameBean) {
                val layoutPosition = holder.layoutPosition
//                var clParent: ConstraintLayout = holder.getView<ConstraintLayout>(R.id.cl_parent)
                var tvName: TextView = holder.getView<TextView>(R.id.tv_name)
                var tvValue: TextView = holder.getView<TextView>(R.id.tv_value)
                tvName.text = item.name
                tvValue.text = item.value

            }
        }
        rvContent?.adapter = mAdapter
//        rvContent?.addItemDecoration(
//            SpacesItemDecoration(
//                SizeUtils.dp2px(12.0f),
//                SizeUtils.dp2px(10.0f),
//                true
//            )
//        )


    }

    private fun initEvnet() {

        viewTop?.setOnClickListener {

            dismiss()
        }

    }

    private fun setDismissDialog() {
        dismiss()
    }


    override fun onDestroy() {
        super.onDestroy()
    }

    override fun beforeDismiss() {
        super.beforeDismiss()


    }


//    fun setOnDialogSureListener(onPopSureListener: OnPositionTListener<TelSecondCategory>?) {
//        this.onPopSureListener = onPopSureListener
//    }
}